package com.example.controller;

import com.example.impl.OrderServiceImpl;
import com.example.model.WxbCustomer;
import com.example.model.WxbOrder;
import com.example.model.vo.Result;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderServiceImpl orderService;

    @RequestMapping("/findByAll")
    public String findAll(Model model){
      WxbCustomer wxbCustomer = (WxbCustomer) SecurityUtils.getSubject().getPrincipal();
        List<WxbOrder> orders= orderService.findAll(wxbCustomer.getCustomerId());

        model.addAttribute("orders",orders);

      return "generalize";
    }

    @RequestMapping("/updatestate")
    @ResponseBody
    public Result updateState(@RequestBody HashMap<String,Object> map){

        int state  =(Integer)map.get("state");
        List<String> ids = (List<String>) map.get("ids");
        try {
            orderService.updateState(state,ids);
            return new Result(true,"操作成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"操作失败");
        }
    }


}
